package tags;
import java.util.HashSet;
import java.util.Iterator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

public class MyIteratorTag extends TagSupport
{
	HashSet makers;
	Iterator i;
	String next;
	String var;
	public MyIteratorTag()
	{
		
	}
	
	public int doAfterBody() throws JspException
	{
		System.out.println("doAfterBody()");
		if(i.hasNext())
		{
			next = (String)i.next();
			System.out.println(var + " = " + next);
			pageContext.setAttribute(var, next);
			return EVAL_BODY_AGAIN;
		}
		return SKIP_BODY;
	}
	
	public void setMakers(HashSet c)
	{
		System.out.println("setMakers(" + c + ")");
		makers = c;
		i = makers.iterator();
	}
	
	public void setVar(String n)
	{
		var = n;
	}
	
	public int doStartTag() throws JspException
	{
		System.out.println("doStartBody()");
		if(i.hasNext())
		{
			next = (String)i.next();
			System.out.println(var + " = " + next);
			pageContext.setAttribute(var, next);
			return EVAL_BODY_INCLUDE;
		}
		return SKIP_BODY;
	}
	
	public int doEndTag() throws JspException
	{
		System.out.println("doEndTag()");
		return EVAL_PAGE;
	}
}
